<?php
/**
* Admin for CMS settings
*
* @author Mario Schillermann <info@rockit-flash.com>
* @encoding UTF-8 äöüßÖÄÜ
* @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
* @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @package Page
* @subpackage Index
* @link $HeadURL$
* @version SVN: $Id$
* @phpVersion >=5
* @todo
*/

class Admin_AppController extends Zend_Controller_Action
{
    private $_identity;

    /**
     * Initialize the general options
     *
     * @return void
     */
    public function init()
    {
        $this->_helper->layout->disableLayout();

        $auth = Zend_Auth::getInstance();
        $this->_identity = $auth->getIdentity();
    }
    /**
     * Index
     *
     * @return void
     */
    public function indexAction()
    {
        $app = $this->getRequest()->path;
        $appAction = $this->getRequest()->param;
        $appClass = ucfirst($app) . "_Model_App";
        $configData = array();

        if (empty($appAction)) {
            $appAction = 'index';
        }
        
        if (class_exists($appClass) && method_exists($appClass, $appAction)) {

            $config = $appClass::$appAction($this->getRequest());
            $this->loadDesktop($config, $appAction, $app);
            $this->loadHeadScript($appAction);
        } else {
            $this->_forward($appAction, 'app', $app);
        }
    }
        /*       
        
        $this->view->store = $this->getRequest()->store;
        
        
        

        
        $this->view->username = $this->_identity['username'];
        $this->view->app = $app;
        $this->view->action = $action;
        
        // create top app navi
        $buttonClass = ucfirst($app) . "_Form_App";
        $buttonAction = $action . "Button";
        
        if (method_exists($buttonClass, $buttonAction)) {

            $buttons = $buttonClass::$buttonAction($this->getRequest());
            if($buttons) {
                foreach ($buttons as $button) {

                    if(is_array($button["url"])) {
                        $url = $this->view->url($button["url"]);
                    } else {
                        $url = '#';
                    }

                    $this->view->appButton .= '<a href="' . $url;
                    foreach ($button['event'] as $type => $event) {
                        $this->view->appButton .= '"' . $type . '="' . $event;
                    }
                    $this->view->appButton .= '">' . $button['name'].'</a>';
                }
            }
        }
        if (isset($buttonClass::$navi)) {
            $this->view->appNavi =
                '<tr height="48px">' .
                '<td id="appNavi">';
            foreach ($buttonClass::$navi as $type => $name) {
                $this->view->appNavi .=
                    '<a href="'.$this->view->url(array("param"=>$type)).'" class="appButton">' .
                    '<img src="'.$baseUrl.'/images/iconEdit.png"/>' .
                    '<p>'.$name.'</p>' .
                    '</a>';
            }
            $this->view->appNavi .=  '</td></tr>';
        }*/
  //  }
    /**
     * Load Desktop
     * 
     * @param array $config
     * @param string $appAction
     * @param string $app 
     */
    protected function loadDesktop (&$config, &$appAction, &$app) {
        
        $this->_helper->layout->setLayout('app');
        $this->view->app = $app;
        $this->view->appAction = $appAction;
    }
    /**
     * Head Script for Layout
     * 
     * @param string &$appAction
     */
    protected function loadHeadScript (&$appAction) {

        $baseUrl = $this->view->baseUrl(
            "application" . DIRECTORY_SEPARATOR .
            "modules" . DIRECTORY_SEPARATOR .
            "admin" . DIRECTORY_SEPARATOR .
            "public" . DIRECTORY_SEPARATOR .
            "desktop");

        $this->view
             ->headLink()
             ->appendStylesheet(
                 $this->view
                      ->baseUrl($baseUrl . DIRECTORY_SEPARATOR .
                                "css" . DIRECTORY_SEPARATOR .
                                "main.css"
                               )
               )
             ->appendStylesheet(
                 $this->view
                      ->baseUrl("application" . DIRECTORY_SEPARATOR .
                                "modules" . DIRECTORY_SEPARATOR .
                                $app . DIRECTORY_SEPARATOR .
                                "public" . DIRECTORY_SEPARATOR .
                                "app" . DIRECTORY_SEPARATOR .
                                "css" . DIRECTORY_SEPARATOR .
                                $action . ".css"
                               )
               );
        $this->view
             ->headScript()
             ->appendFile($baseUrl . DIRECTORY_SEPARATOR .
                          "js" . DIRECTORY_SEPARATOR .
                          "main.js");
        $this->view->headScript()->appendFile($this->view->baseUrl("library" . DIRECTORY_SEPARATOR .
                                "editor" . DIRECTORY_SEPARATOR .
                                "edit_area". DIRECTORY_SEPARATOR) .
                                "edit_area_full.js", 'text/javascript');
    }
}